package com.qf.service.impl;

import com.qf.dao.BookDao;
import com.qf.dao.impl.BookDaoImpl;
import com.qf.domain.Book;
import com.qf.domain.PageBean;
import com.qf.service.BookService;

import java.util.List;

public class BookServiceImpl implements BookService {
    private BookDao bookDao=new BookDaoImpl();
    @Override
    public List<Book> findAll() {
        return bookDao.selectAll();
    }

    @Override
    public void removeBook(int bookId) {
        bookDao.delete(bookId);
    }

    @Override
    public Book findById(int bookId) {
        return bookDao.selectById(bookId);
    }

    @Override
    public void modify(Book book) {
        bookDao.update(book);
    }

    @Override
    public void addBook(Book book) {
        bookDao.insert(book);
    }

    @Override
    public PageBean<Book> findByPage(int page_num, int page_size) {
       long totalSize=bookDao.selectCount();
       List<Book> data=bookDao.selectPage(page_num,page_size);
        PageBean<Book> pageBean=new PageBean<Book>(page_size,page_num,totalSize,data);
        return pageBean;
    }

    @Override
    public PageBean<Book> findByPage(int page_num, int page_size, String where, List<Object> params) {
        long totalSize=bookDao.selectCount(where,params);
        List<Book> data=bookDao.selectPage(page_num,page_size,where,params);
        //PageBean(int pageSize, int pageNum, long totalSize, List<T> data)
        PageBean<Book> pageBean=new PageBean<Book>(page_size,page_num,totalSize,data);
        return pageBean;
    }
}
